import {Select} from "antd";
import React from "react";
const { Option } = Select;

type CustomSelectProps = {
  datalist: {id: any, name: any}[],
  setSelectData: (data: any) => void,
  name: string,
  selectDate: any,
  disabled?: boolean

}
const CustomSelect: React.FC<CustomSelectProps> = ({datalist,disabled= false, setSelectData, name, selectDate}) => {
  const onChangeHandler = (value: any) => {
    setSelectData(value)
  }
  return (
    <Select
      popupMatchSelectWidth={200}
      allowClear
      showSearch
      disabled = {disabled}
      optionFilterProp="children"
      placeholder={name}
      onClick={(e) => e.stopPropagation()}
      onChange={onChangeHandler}
      value={selectDate || undefined}
    >
      {datalist.map((item) => {
        return (
          <Option value={item.id} key={item.id}>
            {item.name}
          </Option>
        );
      })}
    </Select>
  );
};

export default CustomSelect;
